# coding:utf-8
"""
人脸检测与特征提取的服务
"""
import os
import sys

from flask import Flask 
from flask import jsonify
from flask import request
from detector import FaceDetector


pwd = os.path.dirname(os.path.realpath(__file__))
predictor_path = os.path.join(pwd, 'dlib_models/shape_predictor_5_face_landmarks.dat')
face_rec_model_path = os.path.join(pwd, 'dlib_models/dlib_face_recognition_resnet_model_v1.dat')


sys.path.append(os.path.join(pwd, "face_detect"))
face_detector = FaceDetector(predictor_path, face_rec_model_path)


app = Flask(__name__)

@app.route('/detectbyurl', methods=['POST'])
def detect_by_url():
    jsonrequest = request.json
    imgurl = jsonrequest['imageurl']
    return jsonify(face_detector.detect_by_url(imgurl))


if __name__ == "__main__":
    app.run(host="0.0.0.0")